package com.jxpanda.spring.module.wechat.component.message.handler;

import com.jxpanda.spring.module.wechat.component.message.pojo.WechatXmlMessage;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Panda
 */
public class WechatReceivedXmlMessageHandlers {

    private final Map<String, WechatReceivedXmlMessageHandler<?>> handlerMap = new HashMap<>(8);

    public <M extends WechatXmlMessage, H extends WechatReceivedXmlMessageHandler<M>> void addHandler(String msgType, H handler) {
        handlerMap.put(msgType, handler);
    }

    @SuppressWarnings("unchecked")
    public <M extends WechatXmlMessage, H extends WechatReceivedXmlMessageHandler<M>> H getHandler(String msgType) {
        return (H) handlerMap.get(msgType);
    }

}
